﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>南京化工职业技术学院资源共享平台--主页</title>
<link href="res/css/css.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="res/js/jquery-1.2.6.js"></script>
<script type="text/javascript" src="res/js/util.js"></script>
<script type="text/javascript">
	function addFileField() {
		var container = document.getElementById("uploadfield");
		var newFileField = document.createElement("input");
		var id = (new Date()).valueOf();
		newFileField.type="file";
		newFileField.name="upload";
		newFileField.id=id;
		newFileField.size=46;
		newFileField.style.width="80%";
		newFileField.style.border="1px #5596be solid";
		newFileField.style.height="24px";
		newFileField.style.lineHeight="24px";
		container.appendChild(newFileField);
		container.innerHTML = container.innerHTML + "<a id=\"a" + id + "\" href=\"javascript:removeFileField(" + id +");\">删除</a>";
		var br = document.createElement("br");
		br.id="br" + id;
		container.appendChild(br);
		//update the whole height
		var uploaddiv = document.getElementById("uploaddiv");
		var heightStr = uploaddiv.style.height;
		var nowHeight = parseInt(heightStr.substring(0,heightStr.lastIndexOf("px"))) + 20;
		uploaddiv.style.height = nowHeight + "px";
	}
	function removeFileField(id) {
		var container = document.getElementById("uploadfield");
		container.removeChild(document.getElementById(id));
		container.removeChild(document.getElementById("a" + id));
		container.removeChild(document.getElementById("br" + id));
		//update the whole height
		var uploaddiv = document.getElementById("uploaddiv");
		var heightStr = uploaddiv.style.height;
		var nowHeight = parseInt(heightStr.substring(0,heightStr.lastIndexOf("px"))) - 20;
		uploaddiv.style.height = nowHeight + "px";
	}
	
	function onload() {
		var shareType = <%=session.getAttribute("shareType")%>;
		if(shareType == null) {
			shareType = 0;	//default is comm shared
		}
		var shareTypeRadio = document.getElementsByName("shareWay");
		for(var i = 0;i<shareTypeRadio.length;i++) {
			var radioItem = shareTypeRadio[i];
			if(radioItem.value == shareType) {
				radioItem.checked = "checked";
			}
			radioItem.disabled = "disabled";
		}
		if(shareType == 1) {
			//share in course ,no type
			document.getElementById("superType").disabled="disabled";
			document.getElementById("type").disabled="disabled";
		}
		$.post("res/getResType.action",{"superId":"0"},resTypeCB,"json");
	}
	function resTypeCB(data) {
		var superType = $("#superType");
		if(data == null || data == "") {
			superType.html("<option>暂无分类</option>");
			return;
		}
		var json = data.types;
		superType.html("<option value=\"0\">请选择</option>");
		for(var i = 0;i<json.length;i++) {
			var item = json[i];
			superType.append("<option value=\""+ item.id + "\">" + item.name + "</option>");
		}
	}
	
	function getTypeItem(value) {
		if(value == 0) {
			var superType = $("#type");
			superType.html("<option value=\"0\">请选择</option>");
			return;
		}
		$.post("res/getResType.action",{"superId":value},resTypeItem,"json");
	}
	function resTypeItem(data) {
		var superType = $("#type");
		if(data == null || data == "") {
			superType.html("<option>暂无分类</option>");
			return;
		}
		var json = data.types;
		superType.html("<option value=\"0\">请选择</option>");
		for(var i = 0;i<json.length;i++) {
			var item = json[i];
			superType.append("<option value=\""+ item.id + "\">" + item.name + "</option>");
		}
	}
	
	function check() {
		//验证共享方式
		var shareWay = document.getElementsByName("shareWay");
		for(var i = 0;i<shareWay.length;i++) {
			if(shareWay[i].checked == true) {
				document.getElementById("shareType").value = shareWay[i].value;
			}
		}
		if(document.getElementById("shareType").value == 0) {
			//验证所选类别
			var type = document.getElementById("type");
			if(type.value == 0) {
				alert("请选择资源类别！");
				return ;
			}
		}
		//验证要上传的文件
		var files = document.getElementsByName("upload");
		if(files == null) {
			alert("请选择要上传的资源！");
			return ;
		}
		//验证资源描述
		var resDes = document.getElementById("resDes");
		if(resDes.value == null || resDes.value == "" || jmz.GetLength(resDes.value) < 20) {
			alert("请填写20字以上的资源描述！");
			return ;
		}
		document.forms[0].submit();
	}
</script>
</head>
<body onload="javascript:onload();">
<div id="header">
   <div id="top">
       <ul>
            <li><marquee onmouseover=this.stop() onmouseout=this.start()>今日访问：${accessCount }&nbsp;&nbsp;共享资源总数：${resCount }&nbsp;&nbsp;注册用户总数：${userCount }&nbsp;&nbsp;资源共享达人：${daUser.realName }&nbsp;&nbsp;资源下载热度：${faRes.name }</marquee></li>
       </ul>
   </div>
   <div id="bottom">
       <div id="bleft"><img src="res/images/share_05.jpg" width="387" height="65" />
       </div>
   </div>
</div>
<div id="content" style="height:auto;">
   <div class="mt">
      <h3><a href="<%=basePath%>entry.jsp">首页</a>>>资源上传</h3>
   </div>
   <div id="uploaddiv" style="margin:10px;height:500px;">
   	<div style="float:left;width:70%;">
   <form action="njcc/upload.action" method="post" enctype="multipart/form-data" onsubmit="return check();">
   		<table style="width:100%;">
   			<tr>
   				<td colspan="2" height="20px;"></td>
   			</tr>
   			<tr>
   				<td width="15%" style="font-size:14px;text-align:left;height:40px;"><a style="font-size:14px;">共享方式：</a></td>
   				<td width="80%" style="font-size:14px;text-align:left;"><input type="hidden" id="shareType" name="shareType" value="0" /><input type="radio" id="defaultShare" name="shareWay" value="0" />默认共享<input type="radio" id="courseShare" name="shareWay" value="1" />课程内</td>
   			</tr>
   			<tr>
   				<td width="15%" style="font-size:14px;text-align:left;height:40px;"><a style="color:red;">(*)</a><a style="font-size:14px;">资源类别：</a></td>
   				<td width="80%" style="font-size:14px;text-align:left;">
   					<select id="superType" style="width:150px;border:1px solid #5596be" onchange="javascript:getTypeItem(this.value);">
   					</select>
   					<select id="type" name="type" style="width:150px;border:1px solid #5596be">
   						<option value="0">请选择</option>
   					</select>
   				</td>
   			</tr>
   			<tr>
   				<td width="15%" style="font-size:14px;text-align:left;vertical-align: top;"><a style="color:red;">(*)</a><a style="font-size:14px;">选择文件：</a></td>
   				<td width="80%" style="font-size:14px;text-align:left;" id="uploadfield"><input style="width:80%" class="upload_button" size="46" type="file" name="upload" /><a href="javascript:addFileField();">增加文件</a></td>
   			</tr>
   			<tr>
   				<td width="15%" style="font-size:14px;text-align:left;height:30px;"></td>
   				<td width="80%" style="font-size:14px;color:gray;text-align:left;">(支持上传单文件10M以内的文件)</td>
   			</tr>
   			<tr>
   				<td width="15%" style="font-size:14px;text-align:left;height:40px;"><a style="font-size:14px;">关键词（Tag）：</a></td>
   				<td width="80%" style="font-size:14px;text-align:left;"><input style="width:40%" class="upload_button" size="46" type="text" name="tag" /></td>
   			</tr>
   			<tr>
   				<td width="15%" style="font-size:14px;text-align:left;height:30px;"></td>
   				<td width="80%" style="font-size:14px;color:gray;text-align:left;">(多个关键字请用空格分隔)</td>
   			</tr>
   			<tr>
   				<td width="15%" style="font-size:14px;text-align:left;height:30px;"><a style="color:red;">(*)</a><a style="font-size:14px;">资源分：</a></td>
   				<td width="80%" style="font-size:14px;text-align:left;">
   					<select name="resScore"  style="width:150px;border:1px solid #5596be">
   						<option value="0">0</option>
   						<option value="1">1</option>
   						<option value="2">2</option>
   						<option value="3">3</option>
   						<option value="4">4</option>
   						<option value="5">5</option>
   						<option value="6">6</option>
   						<option value="7">7</option>
   						<option value="8">8</option>
   						<option value="9">9</option>
   						<option value="10">10</option>
   					</select>
   					<a style="color:red;">(注意：该项选择后无法更改)</a>
   				</td>
   			</tr>
   			<tr>
   				<td width="15%" style="font-size:14px;text-align:left;height:40px;"><a style="font-size:14px;">资源缩略图：</a></td>
   				<td width="80%" style="font-size:14px;text-align:left;"><input style="width:80%" class="upload_button" size="46" type="file" name="resIcon" /></td>
   			</tr>
   			<tr>
   				<td width="15%" style="font-size:14px;text-align:left;vertical-align: top;"><a style="color:red;">(*)</a><a style="font-size:14px;">资源描述：</a></td>
   				<td width="80%" style="font-size:14px;text-align:left;"><textarea style="width:80%;height:100px;" class="upload_button" id="resDes" name="resDes"></textarea></td>
   			</tr>
   			<tr>		
   				<td colspan="3" height="40px;">
   					<input type="hidden" name="folderId" value="${folderId }" id="folderId" />
   					<input type="hidden" name="classId" value="${classId }" id="classId" />
   					<a href="javascript:check();"><img src="res/images/btn_submit.png" alt="上传资源" /></a>
   				</td>
   			</tr>
   		</table>
   	</form>
   	</div>
   	<div style="float:right;width:30%;">
   		<table style="margin:15px;">
   			<tr>
   				<td style="text-align:left;font-size:14px;">
   					<a style="color:red;">上传提示：</a><br/>
					存储空间：不限<br/>
					存储时间：永久<br/>
					支持格式：<br/>
					严禁上传任何政治敏感，色情，侵权的资料。<br/>
				</td>
   			</tr>
   		</table>
   	</div>
   </div>
	<div id="banquan">
      <ul>
       		<li>南京化工职业技术学院--资源共享网 <img src="res/images/pic.gif" width="50" height="12" /></li>           
           	<li>诚聘英才 | 友情链接 | 联系我们</li> 
            <li>版权所有©南京化工职业技术学院 ICP：沪B2-20030192 </li>
  		</ul>
	</div>
	</div>
</body>
</html>
